package com.redare.dev.smart.generator.workbench.listener;

import com.redare.dev.smart.generator.sdk.notice.ICodeGenPullListener;
import com.redare.dev.smart.generator.sdk.pojo.CodeGroup;
import com.redare.dev.smart.generator.sdk.pojo.GenPath;
import com.redare.dev.smart.generator.workbench.config.WebConfig;
import com.redare.devframework.common.pojo.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author yangqy on 2021/10/9
 * @date 2021/10/9 下午3:44
 */
public class CodeGenPullListener implements ICodeGenPullListener {

    @Autowired
    WebConfig webConfig;

    @Override
    public CommonResult<GenPath> getCodeGroupGenPath(CodeGroup codeGroup) {
        if (codeGroup == null) {
            return CommonResult.returnFailsWrapper("参数错误");
        } else {
            String name = codeGroup.getName();
            GenPath path = null;
            switch (name){
                case "sdk":
                    path = new GenPath(webConfig.getProjectDir()+"/"+webConfig.getProjectSdkName()+"/src/main/java/",
                            webConfig.getProjectSdkPackage());
                    break;
                case "sdk-impl":
                    path = new GenPath(webConfig.getProjectDir()+"/"+webConfig.getProjectServiceName()+"/src/main/java/",
                            webConfig.getProjectServicePackage());
                    break;
                case "manager-controller":
                case "new-manager-controller":
                    path = new GenPath(webConfig.getProjectDir()+"/"+webConfig.getProjectManagerName()+"/src/main/java/",
                            webConfig.getProjectManagerPackage());
                    break;
                case "manager-ant-grid-view":
                case "ant-pro-components":
                    path = new GenPath(webConfig.getProjectDir()+"/"+webConfig.getProjectManagerName()+"/webappsrc/src/",
                            "");
                    break;
                default:
                    break;
            }
            return CommonResult.returnDataWrapper(path);
        }
    }

}
